﻿@model SMECustomerWebsite.Models.ViewModels.CustomerManager.CustomerPortfolioViewModel
@Html.Action("CustInfo", "System")
<div class="">
    <div class="row">
        <div class="col-md-12">
            <div class="x_panel">
                <div class="x_title">
                    <h2>@SMECustomerWebsite.Core.Resources.Resource.CustPriority</h2>
                    <ul class="nav navbar-right panel_toolbox">
                        <li>
                            <a class="collapse-link"><i class="fa fa-chevron-up"></i></a>
                        </li>
                    </ul>
                    <div class="clearfix"></div>
                </div>
                <div class="x_content">
                    @switch (Model.CurrentUser.GroupIdentifier)
                    {
                        case "1":
                            <table id="cm-customer-portfolio-vip" class="custom_table table table-bordered table-striped jambo_table bootstrap-datatable datatable">
                                <thead class="headings">
                                    <tr>
                                        <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.Zone.ToUpper()</th>
                                        <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.Branch.ToUpper()</th>
                                        <th class="column-title">DAO</th>
                                        <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.MSBONameHeader</th>
                                        <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.CifHeader</th>
                                        <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.NameHeader</th>
                                        <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.IndustryHeader</th>
                                        <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.DateOpenCifHeader</th>
                                        <th class="column-title">TOI @DateTime.Now.AddMonths(-1).Month/@DateTime.Now.Year</th>
                                        <th class="column-title">TOI @DateTime.Now.AddYears(-1).Year</th>
                                        <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.NhomNoHeader.ToUpper()</th>
                                        <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.CustTypeHeader</th>
                                        <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.InfoHeader</th>
                                    </tr>
                                </thead>
                                <tbody></tbody>
                            </table>
                            break;
                        case "2":
                        <table id="cm-customer-portfolio-vip" class="custom_table table table-bordered table-striped jambo_table bootstrap-datatable datatable">
                            <thead class="headings">
                                <tr>
                                    <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.Branch.ToUpper()</th>
                                    <th class="column-title">DAO</th>
                                    <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.MSBONameHeader</th>
                                    <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.CifHeader</th>
                                    <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.NameHeader</th>
                                    <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.IndustryHeader</th>
                                    <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.DateOpenCifHeader</th>
                                    <th class="column-title">TOI @DateTime.Now.AddMonths(-1).Month/@DateTime.Now.Year</th>
                                    <th class="column-title">TOI @DateTime.Now.AddYears(-1).Year</th>
                                    <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.NhomNoHeader.ToUpper()</th>
                                    <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.CustTypeHeader</th>
                                    <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.InfoHeader</th>
                                </tr>
                            </thead>
                            <tbody></tbody>
                        </table>
                            break;
                        case "3":
                        <table id="cm-customer-portfolio-vip" class="custom_table table table-bordered table-striped jambo_table bootstrap-datatable datatable">
                            <thead class="headings">
                                <tr>
                                    <th class="column-title">DAO</th>
                                    <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.MSBONameHeader</th>
                                    <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.CifHeader</th>
                                    <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.NameHeader</th>
                                    <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.IndustryHeader</th>
                                    <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.DateOpenCifHeader</th>
                                    <th class="column-title">TOI @DateTime.Now.AddMonths(-1).Month/@DateTime.Now.Year</th>
                                    <th class="column-title">TOI @DateTime.Now.AddYears(-1).Year</th>
                                    <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.NhomNoHeader.ToUpper()</th>
                                    <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.CustTypeHeader</th>
                                    <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.InfoHeader</th>
                                </tr>
                            </thead>
                            <tbody></tbody>
                        </table>
                            break;
                        case "4":
                        <table id="cm-customer-portfolio-vip" class="custom_table table table-bordered table-striped jambo_table bootstrap-datatable datatable">
                            <thead class="headings">
                                <tr>
                                    <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.CifHeader</th>
                                    <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.NameHeader</th>
                                    <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.IndustryHeader</th>
                                    <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.DateOpenCifHeader</th>
                                    <th class="column-title">TOI @DateTime.Now.AddMonths(-1).Month/@DateTime.Now.Year</th>
                                    <th class="column-title">TOI @DateTime.Now.AddYears(-1).Year</th>
                                    <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.NhomNoHeader.ToUpper()</th>
                                    <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.CustTypeHeader</th>
                                    <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.InfoHeader</th>
                                </tr>
                            </thead>
                            <tbody></tbody>
                        </table>
                            break;
                        default: break;
                    }

                </div>
            </div>
        </div>
    </div>
</div>
@section scripts
{
    <script src="~/Scripts/custom_search_table.js"></script>
    <!-- bootstrap-daterangepicker -->
    <script src="~/scripts/datepicker/moment/moment.min.js"></script>
    <script src="~/scripts/datepicker/datepicker/daterangepicker.js"></script>
    <script src="/scripts/tableeditable/dataTables.rowsGroup.js"></script>
    <script type="text/javascript">
        $(document).ready(function () {
            var totalColumn = [
                            { "sName": "CIF", "bSortable": false },
                            { "sName": "NAME", "bSortable": false },
                            { "sName": "VPB INDUSTRY", "bSortable": false },
                            { "sName": "DATE OPEN CIF", "bSortable": false },
                            { "sName": "TOI", "bSortable": false },
                            { "sName": "TOI 2015", "bSortable": false },
                            { "sName": "NHOM NO", "bSortable": false },
                            { "sName": "CUST TYPE", "bSortable": false },
                            { "sName": "INFO", "bSortable": false }]
            var totalLenCol = 8;
            var totalCifCol = 0;
            switch (@Model.CurrentUser.GroupIdentifier)
            {
                case 1:
                    totalColumn = [
                            { "sName": "REGION", "bSortable": false },
                            { "sName": "BRANCH", "bSortable": false },
                            { "sName": "DAO", "bSortable": false },
                            { "sName": "MSBO", "bSortable": false },
                            { "sName": "CIF", "bSortable": false },
                            { "sName": "NAME", "bSortable": false },
                            { "sName": "VPB INDUSTRY", "bSortable": false },
                            { "sName": "DATE OPEN CIF", "bSortable": false },
                            { "sName": "TOI", "bSortable": false },
                            { "sName": "TOI 2015", "bSortable": false },
                            { "sName": "NHOM NO", "bSortable": false },
                            { "sName": "CUST TYPE", "bSortable": false },
                            { "sName": "INFO", "bSortable": false }];
                    totalLenCol = 12;
                    totalCifCol = 4;
                    break;
                case 2:
                    totalColumn=  [
                            { "sName": "BRANCH", "bSortable": false },
                            { "sName": "DAO", "bSortable": false },
                            { "sName": "MSBO", "bSortable": false },
                            { "sName": "CIF", "bSortable": false },
                            { "sName": "NAME", "bSortable": false },
                            { "sName": "VPB INDUSTRY", "bSortable": false },
                            { "sName": "DATE OPEN CIF", "bSortable": false },
                            { "sName": "TOI", "bSortable": false },
                            { "sName": "TOI 2015", "bSortable": false },
                            { "sName": "NHOM NO", "bSortable": false },
                            { "sName": "CUST TYPE", "bSortable": false },
                            { "sName": "INFO", "bSortable": false }];
                    totalLenCol = 11;
                    totalCifCol = 3;
                    break;
                case 3:
                    totalColumn= [
                            { "sName": "DAO", "bSortable": false },
                            { "sName": "MSBO", "bSortable": false },
                            { "sName": "CIF", "bSortable": false },
                            { "sName": "NAME", "bSortable": false },
                            { "sName": "VPB INDUSTRY", "bSortable": false },
                            { "sName": "DATE OPEN CIF", "bSortable": false },
                            { "sName": "TOI", "bSortable": false },
                            { "sName": "TOI 2015", "bSortable": false },
                            { "sName": "NHOM NO", "bSortable": false },
                            { "sName": "CUST TYPE", "bSortable": false },
                            { "sName": "INFO", "bSortable": false }];
                    totalLenCol = 10;
                    totalCifCol = 2;
                    break;
                default:
                    break;
            }
            var table = $('#cm-customer-portfolio-vip').DataTable({
                "paging": true,
                //fixedHeader: true,
                "order": [[0, 'asc']],
                "bServerSide": true,
                "bProcessing": true,
                "responsive": true,
                "bAutoWidth": false,
                "aLengthMenu": [10, 30, 50, 100],
                "pageLength": 10,
                rowsGroup: [0, 1, 2,3],
                "sAjaxSource": '@Url.Action("CustPriorityData", "CustomerManager")',
                "fnServerData": function (sSource, aoData, fnCallback) {
                    $.ajax({
                        "dataType": 'json',
                        "type": "POST",
                        "url": sSource,
                        "data": aoData,
                        "success": fnCallback
                    });
                },
                "sDom": "<'row-fluid'<'span6'l><'span6'f>r>t<'row-fluid'<'dataTables_wrapper'ip>>",
                "sPaginationType": "simple_numbers",//"full_numbers",
                "aoColumns": totalColumn,
                "aoColumnDefs": [{
                    "aTargets": [totalLenCol],
                    "mRender": function (data, type, full) {
                        return '<a class=\"btn btn-primary btn-xs\" onclick=\"showCustomerInfo(\'' + full[totalCifCol] + '\');\"><i class="fa fa-info"></i></a>';
                    }
                }],
                initComplete: function () {
                    this.api().columns().every(function () {
                        var column = this;
                        switch (column.context[0].aoHeader[0][column.index()].cell.innerText) {
                            case '@Html.Raw(SMECustomerWebsite.Core.Resources.Resource.Zone.ToUpper())':
                                createFilterRegion(column, '@SMECustomerWebsite.Core.Resources.Resource.Zone');
                                break;
                            case '@Html.Raw(SMECustomerWebsite.Core.Resources.Resource.DateOpenCifHeader)':
                                createFilterDate(column);
                                break;
                            case 'TOI @DateTime.Now.AddMonths(-1).Month/@DateTime.Now.AddMonths(-1).Year':
                                createFilterBalanceMulti(column,1);
                                break;
                            case 'TOI @DateTime.Now.AddYears(-1).Year':
                                createFilterBalanceMulti(column,2);
                                break;
                            case '@Html.Raw(SMECustomerWebsite.Core.Resources.Resource.CustTypeHeader)':
                                var option = [{ id: '3', text: 'All' }, { id: '0', text: 'SME Silver' }, { id: '1', text: 'SME Gold' }, { id: '2', text: 'SME Diamond' }]
                                createFilterCustType(column, option);
                                break;
                            case '@Html.Raw(SMECustomerWebsite.Core.Resources.Resource.NhomNoHeader.ToUpper())':
                                createFilterBalanceMulti(column,3);
                                break;
                            case '@Html.Raw(SMECustomerWebsite.Core.Resources.Resource.Branch.ToUpper())':
                                createFilterBranch(column);
                                break;
                            case '@Html.Raw(SMECustomerWebsite.Core.Resources.Resource.MSBONameHeader.ToUpper())':
                                createFilterMSBOName(column, 1);
                                break;
                            case 'DAO':
                                createFilterMSBOName(column, 2);
                                break;
                            default:
                                if (column.index() < totalLenCol) {
                                    var select = $('<input type="text" class="filtet-table">')
                                                            .appendTo($(column.header()))
                                                            .on('keyup change', function () {
                                                                column.search(this.value).draw();
                                                            });
                                }
                                break;

                        }
                    });
                },
                "drawCallback": function (settings) {
                    $('table.custom_table th').removeClass().addClass('column-title');
                }
            });
        })
    </script>
}